Made expected_update_period_in_days an option

Glenn 'devalias' Grant 10 年之前
父節點
當前提交
e42d54f8d1
共有 1 個文件被更改,包括 7 次插入3 次删除
  1. 7 3
      app/models/agents/weather_agent.rb

+ 7 - 3
app/models/agents/weather_agent.rb

@@ -19,6 +19,8 @@ module Agents
19 19
       You must setup an [API key for Wunderground](http://www.wunderground.com/weather/api/) in order to use this Agent with Wunderground.
20 20
 
21 21
       You must setup an [API key for Forecast](https://developer.forecast.io/) in order to use this Agent with ForecastIO.
22
+
23
+      Set `expected_update_period_in_days` to the maximum amount of time that you'd expect to pass between Events being created by this Agent.
22 24
     MD
23 25
 
24 26
     event_description <<-MD
@@ -49,7 +51,7 @@ module Agents
49 51
     default_schedule "8pm"
50 52
 
51 53
     def working?
52
-      event_created_within?(2) && !recent_error_logs?
54
+      event_created_within?(options['expected_update_period_in_days']) && !recent_error_logs?
53 55
     end
54 56
 
55 57
     def key_setup?
@@ -61,7 +63,8 @@ module Agents
61 63
         'service' => 'wunderground',
62 64
         'api_key' => 'your-key',
63 65
         'location' => '94103',
64
-        'which_day' => '1'
66
+        'which_day' => '1',
67
+        'expected_update_period_in_days' => '2'
65 68
       }
66 69
     end
67 70
 
@@ -83,6 +86,7 @@ module Agents
83 86
       errors.add(:base, "location is required") unless location.present?
84 87
       errors.add(:base, "api_key is required") unless key_setup?
85 88
       errors.add(:base, "which_day selection is required") unless which_day.present?
89
+      errors.add(:base, "expected_update_period_in_days is required") unless options['expected_update_period_in_days'].present?
86 90
     end
87 91
 
88 92
     def wunderground
@@ -163,7 +167,7 @@ module Agents
163 167
               'ozone' => value.ozone.to_s
164 168
             }
165 169
             return day
166
-          end    
170
+          end
167 171
         end
168 172
       end
169 173
     end